<extend name="Public/base"/>
<block name="head">
    <!-- DATA TABLES -->
    <link href="__PUBLIC__/plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/plugins/datatables/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/plugins/datatables/extensions/TableTools/css/dataTables.tableTools.min.css" rel="stylesheet" type="text/css" />
</block>

<block name="body">
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body table-responsive">
                        <table id="link-tables" class="table table-bordered table-striped ">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>链接名称</th>
                                <th>链接地址</th>
                                <th>分类</th>
                                <th>排序</th>
                                <th>icon</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="lists" id="links" >
                                <tr data="{$links['id']}">
                                    <td>{$links['id']}</td>
                                    <td>{$links['title']}</td>
                                    <td>{$links['url']}</td>
                                    <td>{$links['category_id']|getOptionsLabel = C('link_category')}</td>
                                    <td>{$links['link_order']}</td>
                                    <td>
                                        <?php
                                            if ($links['icon']):
                                         ?>
                                        <img src="<?php echo $links['icon'] ?>" title="{$links['title']}" style="max-width: 35px" />
                                        <?php endif; ?>
                                    </td>
                                    <td>{$links['remark']}</td>
                                    <td>
                                        <p data-placement="top" data-toggle="tooltip" title="Edit">
                                            <a href="javascript:;"  url="__URL__/edit/id/{$links['id']}" class="ajax-callback">
                                                <button class="btn btn-primary btn-xs"    data-title="Edit" data-toggle="modal" data-target="#edit"><span class="glyphicon  glyphicon-edit"></span> </button>
                                            </a>
                                        </p>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>

                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div><!-- /.col -->
        </div><!-- /.row -->
        </div>
        <include file="add" />
        <include file="edit" />
    </section><!-- /.content -->

</block>
<block name="script">

    <script src="__PUBLIC__/plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {

            iniDataTable("#link-tables",'','__URL__');
            iniAjaxFormDialog('#linkAddForm','#add');
            iniAjaxFormDialog('#linkEditForm','#edit');

        });

        $('.ajax-callback').bind('click',function(){
            ajaxObject.ajaxCallBackFn(this,function(result){
                var data = $.parseJSON(result);

                linkEditForm.title.value = data.title;
                linkEditForm.url.value = data.url;
                linkEditForm.remark.value = data.remark;
                linkEditForm.id.value = data.id;
                linkEditForm.link_order.value = data.link_order;
                if(data.icon){
                    $('.link-thumbnail').attr('src',data.icon);
                }
                var cats = linkEditForm.category_id.options;
                for(var j in cats){
                    if(cats[j].value == data.category_id){
                        cats[j].defaultSelected = true;
                        cats[j].selected = true;
                    }
                }

            });
        });

    </script>

</block>